package com.sxbbc.plat.controller.jz;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.function.common.GetRest;
import com.function.common.RestResponse;
import com.sxbbc.common.basics.exceptions.ThrowJsonException;
import com.sxbbc.common.basics.files.RestUploadFileInfo;
import com.sxbbc.common.basics.files.UploadUtils;
import com.sxbbc.common.basics.rest.RestFactory;
import com.sxbbc.common.basics.utils.calculation.CalcuUtils;
import com.sxbbc.common.basics.utils.statics.DynamicSettingUtils;
import com.sxbbc.common.basics.utils.statics.StaticUtils;
import com.sxbbc.common.core.dto.jz.PropertiesVo;
import com.sxbbc.common.core.entity.jz.*;
import com.sxbbc.common.core.enums.*;
import com.sxbbc.common.core.service.*;
import com.sxbbc.common.core.utils.BasePage;
import com.sxbbc.common.core.utils.FileUtils;
import com.sxbbc.common.core.utils.MultipartFileToFile;
import com.sxbbc.plat.common.ProductMapping;
import com.sxbbc.plat.util.SystemLog;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 商品管理 控制层
 *
 * @author leehao
 * @date 2019-05-06 09:37
 */
@SuppressWarnings("all")
@Controller
public class ProductController {

    @Autowired
    private IProcMainService procMainService;
    @Autowired
    private ProcClassifyMainService procClassifyMainService;
    @Autowired
    private IProcBrandInfoService brandInfoService;
    @Autowired
    private IProcBrandApplyService brandApplyService;
    @Autowired
    private IIndustryService industryService;
    @Autowired
    private IIndustryDetailService industryDetailService;
    @Autowired
    private IProcInterestService procInterestService;
    @Autowired
    private IProGroupConfigService proGroupConfigService;
    @Autowired
    private ProcClassifyMainService classifyMainService;
    @Autowired
    private ProcClassifyShopService classifyShopService;
    @Autowired
    private IProcDescribeService procDescribeService;
    @Autowired
    private IProSkuDetailService proSkuDetailService;
    @Autowired
    private IBExpConfigService bExpConfigService;
    @Autowired
    private IAddressService addressService;
    @Autowired
    private ICustomerLevelInfoService customerLevelInfoService;
    @Autowired
    private BBusinessService bBusinessService;

    /**
     * 行业新增编辑的标记
     */
    private static final int INDUSTRY_MAIN = 1;
    private static final int INDUSTRY_DETAIL = 2;

    /**
     * 商品列表
     *
     * @param request
     * @return org.springframework.web.servlet.ModelAndView
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.SHOW_PRODUCT)
    public ModelAndView showProductList(HttpServletRequest request, BasePage<ProcMain> page, ProcMain procMain) {
        //商品list
        IPage<ProcMain> pageInfo = procMainService.queryProductList(page, procMain);
        //分类list
        List<?> firstList = procClassifyMainService.queryClassifyListAjax(null, ClassifyTypeEnums.PLAT_FORM.getId(), null, 1);

        //商品类型
        List<ProductTypeEnums> typeList = ProductTypeEnums.queryValidList(BusinessTypeEnums.OWN_BUSINESS.getId());
        ModelAndView view = new ModelAndView(ProductMapping.SHOW_PRODUCT);
        view.addObject("firstList", firstList);
        view.addObject("pageInfo", pageInfo);
        view.addObject("typeList", typeList);
        view.addObject("procMain", procMain);
        view.addObject("needApply",DynamicSettingUtils.PRODUCT_NEED_PLAT_APPLY);
        return view;
    }
    
    @RequestMapping(value = ProductMapping.QUERY_PRODUCT)
    @ResponseBody
    public com.sxbbc.common.basics.rest.RestResponse queryProduct(BasePage<ProcMain> page, ProcMain procMain){
        //商品list
        procMainService.queryProductList(page, procMain);
    	return RestFactory.success(page.getRecords());
    }

    @RequestMapping(value = ProductMapping.SHOW_EDIT_PRODUCT)
    public ModelAndView showEditProduct(Integer proId) {
        CalcuUtils calUtil = CalcuUtils.getInstance();
        ProcMain procMain = procMainService.getById(proId);
        BBusiness bBusiness = bBusinessService.getById(procMain.getBid());
        ProGroupConfig proGroupConfig = new ProGroupConfig();
//        if (calUtil.isEquals(procMain.getProType(), ProductTypeEnums.GROUPS.getId())) {
//            proGroupConfig = proGroupConfigService.selectGroupProduct(procMain.getProCode());
//        }
        //商品类型
        List<ProductTypeEnums> procTypeList = new ArrayList<>();
        if (calUtil.isEquals(bBusiness.getBType(),BusinessTypeEnums.OWN_BUSINESS.getId())) {
            procTypeList = ProductTypeEnums.queryValidList(BusinessTypeEnums.OWN_BUSINESS.getId());
        }else if(calUtil.isEquals(bBusiness.getBType(),BusinessTypeEnums.SETTLED.getId())){
            procTypeList = ProductTypeEnums.queryValidList(BusinessTypeEnums.SETTLED.getId());
        }
        //平台一二三级分类
        ProcThirdClassifyMain thirdClassifyMain = new ProcThirdClassifyMain();
        thirdClassifyMain.setLevel(StaticUtils.FIRST_CLASSIFY);
        List<?> firstList = classifyMainService.queryClassifyListByPlat(thirdClassifyMain);
        List<?> secondList = new ArrayList<>();
        List<?> thirdList = new ArrayList<>();
        if (procMain.getMainClassifyFirstId() != null) {
            //一级不为空查询二级
            thirdClassifyMain.setLevel(StaticUtils.SECOND_CLASSIFY);
            thirdClassifyMain.setFirstId(procMain.getMainClassifyFirstId());
            secondList = classifyMainService.queryClassifyListByPlat(thirdClassifyMain);
        }
        if (procMain.getMainClassifyFirstId() != null && procMain.getMainClassifySecondId() != null) {
            //一二级不为空查询三级
            thirdClassifyMain.setLevel(StaticUtils.THIRD_CLASSIFY);
            thirdClassifyMain.setFirstId(procMain.getMainClassifyFirstId());
            thirdClassifyMain.setSecondId(procMain.getMainClassifySecondId());
            thirdList = classifyMainService.queryClassifyListByPlat(thirdClassifyMain);
        }
        //商家分类
        ProcThirdClassifyShop thirdClassifyShop = new ProcThirdClassifyShop();
        thirdClassifyShop.setTargetId(bBusiness.getId());
        thirdClassifyShop.setLevel(StaticUtils.FIRST_CLASSIFY);
        List<?> shopList = classifyShopService.queryClassifyListByBusiness(thirdClassifyShop);
        //商品标签
        List<ProcLabelEnums> labelList = ProcLabelEnums.queryList();
        //计价方式
        List<ValuationTypeEnums> valuationList = ValuationTypeEnums.queryList();
        //店铺权益
        QueryWrapper<ProcInterest> interWr = new QueryWrapper<>();
        interWr.eq("type", StaticUtils.PRODUCT_INTEREST_BUSINESS).eq("targetid", bBusiness.getId());
        String[] inters = {};
        if (StringUtils.isNotBlank(procMain.getInterest())) {
            inters = procMain.getInterest().split(",");
        }
        List<ProcInterest> interList = procInterestService.list(interWr);
        for (ProcInterest procInterest : interList) {
            for (String i : inters) {
                if (CalcuUtils.getInstance().isEquals(procInterest.getId(),Integer.parseInt(i))) {
                    procInterest.setCheckFlag("checked");
                }
            }
        }
        //商品属性数据
        List<PropertiesVo> propertiesList = procDescribeService.getProcPropertiesList(procMain.getProCode());
        //sku数据
        List<PropertiesVo> skuList = procDescribeService.getProcSkuList(procMain.getProCode());
        //sku详情
        List<ProSkuDetail> skuDetailList = proSkuDetailService.querySkuListByProCode(procMain.getProCode());
        //运费模板
        QueryWrapper<BExpConfig> expWrapper = new QueryWrapper<>();
        expWrapper.eq("bid",bBusiness.getId()).eq("status",StaticUtils.STATUS_YES);
        List<BExpConfig> expList = bExpConfigService.list(expWrapper);
        //商品详情描述
        ProcDescribe describe = procDescribeService.selectByProCode(procMain.getProCode());
        //地址
        Address address = new Address();
        address.setPid(StaticUtils.ADDRESS_COUNTRY);
        List<Address> addressList = addressService.queryAddressByParentId(address);
        List<Address> cityList = new ArrayList<>();
        if (procMain.getProduceCity() != null) {
            address.setPid(procMain.getProducePro());
            cityList = addressService.queryAddressByParentId(address);
        }
        //会员等级
        List<CustomerLevelInfo> levelList = customerLevelInfoService.list();
        levelList.forEach(x -> x.setCheckFlag("disabled"));
        ModelAndView view = new ModelAndView(ProductMapping.SHOW_EDIT_PRODUCT);
        view.addObject("proc", procMain);
        view.addObject("businessCode", bBusiness.getBusinessCode());
        view.addObject("procTypeList", procTypeList);
        view.addObject("firstList", firstList);
        view.addObject("secondList", secondList);
        view.addObject("thirdList", thirdList);
        view.addObject("shopList", shopList);
        view.addObject("labelList", labelList);
        view.addObject("valuationList", valuationList);
        view.addObject("interList", interList);
        view.addObject("propertiesList", propertiesList);
        view.addObject("skuList", skuList);
        view.addObject("skuDetailList", skuDetailList);
        view.addObject("expList", expList);
        view.addObject("describe", describe);
        view.addObject("addressList", addressList);
        view.addObject("cityList", cityList);
        view.addObject("levelList", levelList);
        view.addObject("proGroupConfig", proGroupConfig);
        view.addObject("needProperties", DynamicSettingUtils.PRODUCT_PROPERTIES_NEED);
        return view;
    }

    /**
     * 处理商品状态
     * @param procMain 商品信息
     * @author leehao
     * @return com.function.common.RestResponse
     */
    @RequestMapping(value = ProductMapping.HANDLE_PRODUCT_STATUS)
    @ResponseBody
    @SystemLog(methods = "平台更改商品状态", module = "商品管理")
    public RestResponse handleProductStatus(ProcMain procMain) {
        if (procMain.getId() == null) {
            return GetRest.getFail("获取商品信息失败");
        }
        RestResponse result = procMainService.handleProductStatus(procMain);
        return result;
    }

    /**
     * 批量处理商品状态
     *
     * @param type  类型
     *              1 上架
     *              2 下架
     *              3 审核
     * @param idArr 被选中的id组
     * @return com.function.common.RestResponse
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.HANDLE_PRODUCT_STATUS_BATCH)
    @ResponseBody
    @SystemLog(methods = "批量处理商品状态", module = "商品管理")
    public RestResponse handleProductStatusBatch(Integer type, String idArr) {
        if (type == null) {
            return GetRest.getFail("请选择要操作的类型！");
        }
        if (StringUtils.isBlank(idArr)) {
            return GetRest.getFail("没有数据被选中！");
        }else{
            idArr = idArr.replace("\"","");
        }
        String[] ids = idArr.split(",");
        return procMainService.handleProductStatusBatch(type,ids);
    }

    /* ---------------------------- 品牌管理 ---------------------------- */

    /**
     * 品牌列表页面
     *
     * @param page      分页条件
     * @param brandInfo 查询条件
     * @return org.springframework.web.servlet.ModelAndView
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.SHOW_BRAND_LIST)
    public ModelAndView showBrandList(BasePage<ProcBrandInfo> page, ProcBrandInfo brandInfo) {
        Page<ProcBrandInfo> pageInfo = brandInfoService.queryBrandList(page, brandInfo);
        // 一级分类
        ProcThirdClassifyMain thirdClassifyMain = new ProcThirdClassifyMain();
        thirdClassifyMain.setLevel(StaticUtils.FIRST_CLASSIFY);
        List<?> firstList = procClassifyMainService.queryClassifyListByPlat(thirdClassifyMain);
        // 商家名称
        ModelAndView view = new ModelAndView(ProductMapping.SHOW_BRAND_LIST);
        view.addObject("pageInfo", pageInfo);
        view.addObject("firstList", firstList);
        view.addObject("brand", brandInfo);
        return view;
    }

    @RequestMapping(ProductMapping.SHOW_EDIT_BRAND)
    public ModelAndView showEditBrand(Integer id) {
        ProcBrandInfo brand = brandInfoService.getById(id);
        ProcThirdClassifyMain thirdClassifyMain = new ProcThirdClassifyMain();
        thirdClassifyMain.setLevel(StaticUtils.FIRST_CLASSIFY);
        List<?> firstList = procClassifyMainService.queryClassifyListByPlat(thirdClassifyMain);
        ModelAndView view = new ModelAndView(ProductMapping.SHOW_EDIT_BRAND);
        view.addObject("brand", brand);
        view.addObject("firstList", firstList);
        return view;
    }

    /**
     * 新增/编辑品牌
     *
     * @param request
     * @param imgUrl    品牌图片
     * @param brandInfo 品牌对象
     * @return com.function.common.RestResponse
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.EDIT_BRAND_INFO)
    @ResponseBody
    @SystemLog(methods = "保存商品品牌", module = "商品管理")
    public RestResponse editBrandInfo(HttpServletRequest request,
                                      @RequestParam(required = false) MultipartFile imgUrl,
                                      ProcBrandInfo brandInfo) {
        if (StringUtils.isBlank(brandInfo.getName())) {
            return GetRest.getFail("请输入品牌名称");
        }
        if (brandInfo.getId() == null && imgUrl == null) {
            return GetRest.getFail("请上传品牌图片");
        }
        /*RestUploadFileInfo result = UploadUtils.getInstance().uploadFileQN(imgUrl);
        if (result.isStatus()) {
            brandInfo.setUrl(result.getData());
        } else if (!result.isStatus() && imgUrl != null) {
            return GetRest.getFail("图片上传失败");
        }*/

        try {
            File fe= MultipartFileToFile.multipartFileToFile(imgUrl);
            String url = FileUtils.up(fe);
            brandInfo.setUrl(url);
        }catch (Exception e){
            return GetRest.getFail("图片上传失败，请重试");
        }

        // 对应商家id，为0表示平台新增
        brandInfo.setTargetId(0);
        // 设置品牌类型为平台品牌
        brandInfo.setType(BrandTypeEnums.BRAND.getId());
        boolean save = brandInfoService.saveOrUpdate(brandInfo);
        if (!save) {
            throw new ThrowJsonException("品牌信息保存失败");
        }
        return GetRest.getSuccess("保存成功");
    }

    /**
     * 通过id删除品牌
     *
     * @param request
     * @param id      品牌id
     * @return boolean
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.DELETE_BRAND)
    @ResponseBody
    @SystemLog(methods = "删除商品品牌信息", module = "商品管理")
    public boolean deleteBrandById(HttpServletRequest request, Integer id) {
        return brandInfoService.removeById(id);
    }

    /**
     * 品牌审核页面
     *
     * @param page  分页条件
     * @param apply 查询条件
     * @return org.springframework.web.servlet.ModelAndView
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.SHOW_BRAND_APPLY_LIST)
    public ModelAndView showBrandApplyList(BasePage<ProcBrandApply> page, ProcBrandApply apply) {
        Page<ProcBrandApply> pageInfo = brandApplyService.queryBrandApplyList(page, apply);
        List<BrandTypeEnums> brandList = BrandTypeEnums.queryList();
        ModelAndView view = new ModelAndView(ProductMapping.SHOW_BRAND_APPLY_LIST);
        view.addObject("pageInfo", pageInfo);
        view.addObject("brandList", brandList);
        view.addObject("apply", apply);
        return view;
    }

    /**
     * 处理品牌申请
     *
     * @param id     申请记录id
     * @param status 2审核通过，3审核驳回
     * @return com.function.common.RestResponse
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.HANDLE_BRAND_APPLY)
    @ResponseBody
    @SystemLog(methods = "处理品牌申请", module = "商品管理")
    public RestResponse handleBrandApply(Integer id, Integer status) {
        return brandApplyService.handleBrandApply(id, status);
    }

    /* ------------------------- 行业管理 -------------------------*/

    /**
     * 行业管理页面
     *
     * @param page     分页条件
     * @param industry 查询条件
     * @return org.springframework.web.servlet.ModelAndView
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.SHOW_INDUSTRY_LIST)
    public ModelAndView showIndustryList(BasePage<Industry> page, Industry industry) {
        Page<Industry> pageInfo = industryService.queryIndustryAndDetail(page, industry);
        // 一级分类
        ProcThirdClassifyMain thirdClassifyMain = new ProcThirdClassifyMain();
        thirdClassifyMain.setLevel(StaticUtils.FIRST_CLASSIFY);
        List<?> firstList = procClassifyMainService.queryClassifyListByPlat(thirdClassifyMain);
        ModelAndView view = new ModelAndView(ProductMapping.SHOW_INDUSTRY_LIST);
        view.addObject("pageInfo", pageInfo);
        view.addObject("firstList", firstList);
        view.addObject("industry", industry);
        return view;
    }

    /**
     * 新增/编辑主行业/子行业
     *
     * @param id       主/子行业id
     * @param detailId 子行业id
     * @param level    级别 1主行业 2子行业
     * @return org.springframework.web.servlet.ModelAndView
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.SHOW_EDIT_INDUSTRY)
    public ModelAndView showEditIndustry(Integer id, Integer detailId, Integer level) {
        Industry industry = null;
        IndustryDetail industryDetail = null;
        if (CalcuUtils.getInstance().isEquals(level, INDUSTRY_MAIN)) {
            //主行业
            industry = industryService.getById(id);
        } else if (CalcuUtils.getInstance().isEquals(level, INDUSTRY_DETAIL)) {
            //子行业
            industryDetail = industryDetailService.getById(detailId);
        }
        // 一级分类
        ProcThirdClassifyMain thirdClassifyMain = new ProcThirdClassifyMain();
        thirdClassifyMain.setLevel(StaticUtils.FIRST_CLASSIFY);
        List<?> firstList = procClassifyMainService.queryClassifyListByPlat(thirdClassifyMain);
        // 行业范围
        List<BusinessScopeEnums> scopeList = BusinessScopeEnums.queryList();
        ModelAndView view = new ModelAndView(ProductMapping.SHOW_EDIT_INDUSTRY);
        view.addObject("scopeList", scopeList);
        view.addObject("firstList", firstList);
        view.addObject("industry", industry);
        view.addObject("industryDetail", industryDetail);
        view.addObject("level", level);
        view.addObject("detailId", detailId);
        view.addObject("indId", id);
        return view;
    }

    /**
     * 编辑主行业信息
     *
     * @param industry 主行业对象
     * @param imgUrl   主行业图片
     * @return com.function.common.RestResponse
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.EDIT_INDUSTRY)
    @ResponseBody
    @SystemLog(methods = "编辑主行业信息", module = "商品管理")
    public RestResponse editIndustry(Industry industry,
                                     @RequestParam(name = "imgUrl", required = false) MultipartFile imgUrl) {
        if (StringUtils.isBlank(industry.getName())) {
            return GetRest.getFail("请输入行业名称");
        }
        if (StringUtils.isBlank(industry.getFirstIds())) {
            return GetRest.getFail("请选择分类");
        }
        /*RestUploadFileInfo result = UploadUtils.getInstance().uploadFileQN(imgUrl);
        if (result.isStatus()) {
            industry.setUrl(result.getData());
        } else if (!result.isStatus() && imgUrl != null) {
            return GetRest.getFail("图片上传失败");
        }*/

        try {
            File fe= MultipartFileToFile.multipartFileToFile(imgUrl);
            String url = FileUtils.up(fe);
            industry.setUrl(url);
        }catch (Exception e){
            return GetRest.getFail("图片上传失败，请重试");
        }

        boolean save = industryService.saveOrUpdate(industry);
        if (!save) {
            throw new ThrowJsonException("保存行业信息异常");
        }
        return GetRest.getSuccess("保存成功");
    }

    /**
     * 编辑子行业信息
     *
     * @param detail 子行业信息
     * @param imgUrl 子行业图片
     * @return com.function.common.RestResponse
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.EDIT_INDUSTRY_DETAIL)
    @ResponseBody
    @SystemLog(methods = "编辑子行业信息", module = "商品管理")
    public RestResponse editIndustryDetail(IndustryDetail detail,
                                           @RequestParam(name = "imgUrl", required = false) MultipartFile imgUrl) {
        if (StringUtils.isBlank(detail.getName())) {
            return GetRest.getFail("请输入子行业名称");
        }
       /* RestUploadFileInfo result = UploadUtils.getInstance().uploadFileQN(imgUrl);
        if (result.isStatus()) {
            detail.setUrl(result.getData());
        } else if (!result.isStatus() && imgUrl != null) {
            return GetRest.getFail("图片上传失败");
        }*/

        try {
            File fe= MultipartFileToFile.multipartFileToFile(imgUrl);
            String url = FileUtils.up(fe);
            detail.setUrl(url);
        }catch (Exception e){
            return GetRest.getFail("图片上传失败，请重试");
        }

        boolean save = industryDetailService.saveOrUpdate(detail);
        if (!save) {
            throw new ThrowJsonException("保存子行业信息失败");
        }
        return GetRest.getSuccess("保存成功");
    }

    /**
     * 处理行业状态
     *
     * @param id     主/子行业的ID
     * @param status 1生效/0失效
     * @param type   1处理主行业/2处理子行业
     * @return boolean
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.HANDLE_INDUSTRY_STATUS)
    @ResponseBody
    @SystemLog(methods = "处理行业状态", module = "商品管理")
    public boolean handleIndustryStatus(Integer id, Integer status, Integer type) {
        boolean update = false;
        switch (type) {
            case 1:
                update = industryService.handleIndustryStatus(id, status);
                break;
            case 2:
                update = industryDetailService.handleIndustryStatus(id, status);
                break;
            default:
                break;
        }
        return update;
    }

    /**
     * 通过主行业ID查询子行业
     *
     * @param pid 主行业ID
     * @return com.function.common.RestResponse
     * @author leehao
     */
    @RequestMapping(value = ProductMapping.QUERY_INDUSTRY_DETAIL_BY_ID)
    @ResponseBody
    public RestResponse queryIndustryDetailById(Integer pid) {
        QueryWrapper<IndustryDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("status", StaticUtils.STATUS_YES).eq("ind_id", pid);
        return GetRest.getSuccess("", industryDetailService.list(wrapper));
    }

    /* ---------------------- 商品权益 ---------------------- */
    @RequestMapping(value = ProductMapping.SHOW_PRODUCT_INTEREST)
    public ModelAndView showProductInterest() {
        QueryWrapper<ProcInterest> wrapper = new QueryWrapper<>();
        wrapper.eq("status",StaticUtils.STATUS_YES);
        List<ProcInterest> list = procInterestService.list(wrapper);
        ModelAndView view = new ModelAndView(ProductMapping.SHOW_PRODUCT_INTEREST);
        view.addObject("list", list);
        return view;
    }

    @RequestMapping(value = ProductMapping.SHOW_PRODUCT_INTEREST_EDIT)
    public ModelAndView showEditProductInterest(Integer id) {
        ProcInterest interest = procInterestService.getById(id);
        ModelAndView view = new ModelAndView(ProductMapping.SHOW_PRODUCT_INTEREST_EDIT);
        view.addObject("interest", interest);
        return view;
    }

    @RequestMapping(value = ProductMapping.EDIT_PRODUCT_INTEREST)
    @ResponseBody
    @SystemLog(methods = "新增/编辑商品权益", module = "商品管理")
    public RestResponse editProductInterest(ProcInterest interest) {
        if (StringUtils.isBlank(interest.getName())) {
            return GetRest.getFail("请输入权益名称");
        }
        if (StringUtils.isBlank(interest.getContent())) {
            return GetRest.getFail("请输入权益内容");
        }
        interest.setType(StaticUtils.PRODUCT_INTEREST_PLATFORM);
        boolean save = procInterestService.saveOrUpdate(interest);
        if (!save) {
            throw new ThrowJsonException("保存权益失败");
        }
        return GetRest.getSuccess("保存成功");
    }

    @RequestMapping(value = ProductMapping.DELETE_PRODUCT_INTEREST)
    @ResponseBody
    @SystemLog(methods = "删除商品权益", module = "商品管理")
    public boolean deleteProductInterest(Integer id) {
        ProcInterest interest = procInterestService.getById(id);
        interest.setStatus(StaticUtils.STATUS_NO);
        return procInterestService.updateById(interest);
    }
}
